<template>
  <div class="home">
    <home_head></home_head>
    <home_search></home_search>
    <home_nav></home_nav>
    <router-view></router-view>
    <footer-menu></footer-menu>
    <rightPopover />
  </div>
</template>

<script>
import home_head from '@/components/home/head.vue';
import home_search from '@/components/home/search.vue';
import home_nav from '@/components/home/nav.vue';
// 底部
import footerMenu from '@/components/home/footerMenu.vue';
// 右侧菜单导航栏
import rightPopover from '@/components/home/rigitPopover'
import { token } from '../../api/code';
import Vue from 'vue';
export default {
  name: '',
  data () {
    return {};
  },
  beforeRouteEnter (to, from, next) {
    token()
      .then(data => {
        if (data.code === 401 || data.code === 403) {
          localStorage.removeItem('ps_Authorization');
          // next(vm => {
          //     vm.$message.error('您的登录状态已失效，请先登录！');
          //     next({ path: '/login' });
          // });
          Vue.prototype.$message.error(`${data.msg}`);
          next({ path: '/login' });
        } else if (!data.success) {
          // next(vm => {
          //     vm.$message.error(`${data.msg}`);
          //     next({ path: '/login' });
          // });
          localStorage.removeItem('ps_Authorization');
          Vue.prototype.$message.error(`${data.msg}`);
          next({ path: '/login' });
        } else {
          next();
        }
      })
      .catch(error => {
        localStorage.removeItem('ps_Authorization');
        Vue.prototype.$message.error(`您的登录状态已失效，请先登录！`);
        next({ path: '/login' });
      });
  },
  components: {
    home_head,
    home_search,
    home_nav,
    footerMenu,
    rightPopover
  }
};
</script>

<style lang="css" scoped>
.home {
    width: 100%;
    height: 100%;
    background: rgba(246, 246, 248, 1);
    opacity: 1;
}
</style>